package savet.util.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 *
 * @author Adisson Marinho
 */
public class ObjectOutputStreamUtil extends ArquivoUtil {

    public Serializable abrirArquivo(File file) throws IOException, ClassNotFoundException {
        if (file != null) {
            FileInputStream in = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(in);
            return (Serializable) ois.readObject();
        }
        return null;
    }

    public void salvarArquivo(File file, Serializable object) throws IOException {
        if (file != null) {
            FileOutputStream out = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(out);
            oos.writeObject(object);
            oos.close();
        }
    }
}
